package com.anolesoft.amljmes.fortysix.controller;

import com.anolesoft.amljmes.fortysix.dto.BaoZhangZhuangEmpDTO;
import com.anolesoft.amljmes.fortysix.dto.MesBzzBindDto;
import com.anolesoft.amljmes.fortysix.service.info.MesBzzBindService;
import com.anolesoft.common.core.constant.HttpStatus;
import com.anolesoft.common.core.domain.LoginUser;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.common.security.util.SecurityUtils;
import com.anolesoft.yr.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping(value="/mesbzzbind")
public class MesBzzBindController {
    @Autowired
    MesBzzBindService mesBzzBindService;

    // 根据配套单明细主键查询
    @PostMapping(value="/queryPtdmxObj",produces= MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult queryMesBzzBind(@RequestBody Map<String, String> map) {
        String ptdmxObj = map.get("objuid");
        System.out.println("ptdmxObj"+ptdmxObj);
        List<MesBzzBindDto> list=mesBzzBindService.queryMesBzzBind(ptdmxObj);
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,list);
    }
    // 根据配套单主键查询
    @PostMapping(value="/queryPtdObj",produces= MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult queryMesBzzBinds(@RequestBody Map<String, String> map) {
        String ptdObj = map.get("objuid");
        System.out.println("ptdObj"+ptdObj);
        List<MesBzzBindDto> list=mesBzzBindService.queryMesBzzBinds(ptdObj);
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,list);
    }

    // 连表查状态绑定数
    @PostMapping(value="/all",produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult queryStateNum(@RequestBody String ptdObj){
        ptdObj = ptdObj.substring(1,ptdObj.length()-1).replace("\"","'");
        System.out.println("_________________---------------------"+ptdObj);
        List<MesBzzBindDto> list = mesBzzBindService.queryStateNum(ptdObj);
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,list);
    }
    // 配套单状态
    @PostMapping(value="/state",produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult queryState(@RequestBody String ptdObj){
        ptdObj = ptdObj.substring(1,ptdObj.length()-1).replace("\"","'");
        System.out.println("_________________---------------------"+ptdObj);
        List<MesBzzBindDto> list = mesBzzBindService.queryState(ptdObj);
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,list);
    }

    // 添加
    @PostMapping(value="/add", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public AjaxResult addMesBzzBind(@RequestBody MesBzzBindDto inFoDtoParam){
        System.out.println(">>>>>>add");
        LoginUser loginUser = SecurityUtils.getLoginUser();
        inFoDtoParam.setBangdingren(loginUser.getEmpUid());
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,mesBzzBindService.addMesBzzBind(inFoDtoParam));
    }

    // 删除
    @PostMapping(value="/delete", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult deleteMesBzzBind(@RequestBody String[] objuids){
        System.out.println(">>>>>>delete");
        List<String> asList = null;
        if (objuids != null) {
            asList = Arrays.asList(objuids);
        }
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,mesBzzBindService.deleteMesBzzBind(asList));
    }

    // 修改
    @PostMapping(value="/update", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult updateMesBzzBind(@RequestBody Map<String,String> map){
        System.out.println(">>>>>>update");
        String objuid = map.get("objuid");
        int num1 = Integer.parseInt(map.get("num1"));
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,mesBzzBindService.updateMesBzzBind(objuid,num1));
    }

    // 检验条码
//    @PostMapping(value="/queryEmpEid",produces = MediaType.APPLICATION_JSON_VALUE)
//    @ResponseBody
//    public AjaxResult queryEmpEid() {
//        List<BaoZhangZhuangEmpDTO> baoZhangZhuangEmpDTOS = mesBzzBindService.queryEmpEid();
//        AjaxResult success = AjaxResult.success();
//        success.put("data", baoZhangZhuangEmpDTOS);
//        return success;
//    }

    // 生成箱号
    @PostMapping(value="/updateXh", produces = MediaType.APPLICATION_JSON_VALUE)
    public AjaxResult updateBindXh(@RequestBody String[] objuids){
        System.out.println(">>>>>>update");
        List<String> asList = null;
        if (objuids != null) {
            asList = Arrays.asList(objuids);
        }
        return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,mesBzzBindService.updateBindXh(asList));
    }
}
